package project.sample.protocol.http;

import java.util.List;

/**
 * @author: WUZH009
 * @date: 2019/8/21 16:44
 **/
public class DefaultHttpRequest implements HttpRequest {

    private List<HttpHeader> headers;
    private String method;
    private String uri;
    private String path;
    private String protocol;
    private String host;
    private byte[] body;

    public DefaultHttpRequest(List<HttpHeader> headers, String method, String uri, String path, String protocol, String host, byte[] body) {
        this.headers = headers;
        this.method = method;
        this.uri = uri;
        this.path = path;
        this.protocol = protocol;
        this.host = host;
        this.body = body;
    }


    @Override
    public List<HttpHeader> headers() {
        return headers;
    }

    @Override
    public HttpHeader header(String name) {
        if (name == null || "".equals(name)) {
            return null;
        }
        for (HttpHeader header : headers) {
            if (name.equals(header.getName())) {
                return header;
            }
        }
        return null;
    }

    @Override
    public String method() {
        return method;
    }

    @Override
    public String uri() {
        return uri;
    }

    @Override
    public String host() {
        return host;
    }

    @Override
    public String path() {
        return path;
    }

    @Override
    public byte[] body() {
        return body;
    }
}
